package com.wt.hrentSystem.common.config;

import com.wt.hrentSystem.common.util.YmlUtil;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Component
public class ServerConfig {
    private String port;
    private String basePath;


    public String getBaseUrl(){
        InetAddress address = null;
        try {
            address = InetAddress.getLocalHost();
        }catch (UnknownHostException e){
            e.printStackTrace();
        }
        YmlUtil.loadYml("application.yml");
        port = String.valueOf(YmlUtil.getValue("server.port"));
        basePath = String.valueOf(YmlUtil.getValue("server.servlet.context-path"));
        return "http://"+address.getHostAddress()+":"+this.port+this.basePath;
    }
}
